<template>
  <div id="list">
    <el-table
      :data="rolelist"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="角色编号" width="250">
      </el-table-column>
      <el-table-column prop="rolename" label="角色名称" width="250">
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启用</el-button
            >
            <el-button type="danger" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" plain @click="edit(scope.row.id)">编 辑</el-button>
            <el-button type="primary" @click="del(scope.row.id)"
              >删 除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import {roledelete}from "../../../requset/api";
import { successAlert,warningAlert } from "../../../util/alert.js";
export default {
  data() {
    return {
      form: {},
    }
  },
  computed:{
    ...mapGetters({
      rolelist: "role/list",
    })
  },
  methods: {
    ...mapActions({
      reqChangeRole: "role/reqChangeRole",
    }),
    edit(id){
      this.$emit("edit",id)
    },
    del(id){
       this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText:"确定",
        cancelButtonText: "取消",
        type:'success',
      }).then(() => {
          roledelete({id:id}).then(res=>{
            if(res.data.code==200){
              successAlert(res.data.msg)
              this.reqChangeRole()
            }else{
              warningAlert(res.data.msg)
            }
          })
        }).catch(() => {
          warningAlert("已取消删除")
        });
    }
  },
  mounted(){
    this.reqChangeRole()
  }
};
</script>

<style lang="scss" scoped>
</style>